{extend name="Public:content"}
{block name="button"}
<!--工具栏 start-->
<div class="row">
    <div class="col-sm-12 m-b-xs">
        <button class="btn btn-white btn-sm" type="button"  onClick="$.Oa.reload()"><i class="fa fa-refresh"></i> 刷新</button>
        {if auth("$classuri/del")}
        <a class="btn btn-danger btn-sm"  title="删除权限" onclick="log_index.del()" ><i class="fa fa-plus"></i> 删除日志</a>
        </button>
        {/if}
    </div>
</div>
<!--工具栏 end-->
{/block}
<!--搜索栏 start-->
{block name="search"}
<form id="log_search_form">
<div class="row">
    <div class="col-sm-2 m-b-xs">
        <div class="input-group m-b"><span class="input-group-addon">操作者</span>
            <input name="username" value="{$Think.get.username|default=''}" placeholder="请输入操作者" class="form-control" type="text">
        </div>
    </div>
    <div class="col-sm-2 m-b-xs">
        <div class="input-group m-b"><span class="input-group-addon">操作行为</span>
            <select name='action' class='form-control m-b'>
                <option value=''> 所有记录 </option>
                <!--{foreach $actions as $action}-->
                <option value='{$action}'>{$action}</option>
                <!--{/foreach}-->
            </select>
        </div>
    </div>
    <div class="col-sm-2 m-b-xs">
        <div class="input-group m-b"><span class="input-group-addon">操作内容</span>
            <input name="content" value="{$Think.get.content|default=''}" placeholder="请输入操作内容" class="form-control" type="text">
        </div>
    </div>

    <div class="col-sm-6 m-b-xs">
        <div class="input-group m-b"><span class="input-group-addon">操作时间</span>
            <input placeholder="开始日期 - 结束日期" class="form-control layer-date" id="range-date" name="date" style="width: 30%">
            <button type="button" class="btn btn-info" style="margin-bottom: 0px; margin-left: 10px;" onclick="log_index.search()">搜索</button>
        </div>
    </div>
</div>
</form>
{/block}
<!--搜索栏 end-->
{block name="content"}
<div class="table-responsive" style="overflow-x:initial">
    <table id="log_table" ></table>
</div>
{/block}
{block name="script"}
<script src="__STATIC__/admin/js/plugins/layer/laydate/laydate.js"></script>
<script type="text/javascript">
    $("input[type='text']").keypress(function (e) {
        var e = e || window.event;
        if (e.keyCode == 13) {
            $(".btn.btn-info").click();
        }
    });
    window.log_index = {
        //定义工具栏
        //toolbar: "#log_index_toolbar",
        //搜索
        search: function(){
            var query_params = {};
            $.each($("#log_search_form").serializeArray(),function(){
                query_params[$(this).attr('name')] = $(this).attr('value');
            });
            $('#log_table').bootstrapTable('refreshOptions',{
                pageNumber : 1,
                queryParams:function(params){
                    var tmp_params = {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
                    var query = $.extend(true,tmp_params,query_params);
                    return query;
                }
            });
        },
        del: function(){ //删除日志
            var ids = $.map($("#log_table").bootstrapTable('getSelections'),function(row){
                return row.id;
            });
            if(ids.length == 0){
                layer.msg("请先选择要删除的记录!");
                return false;
            }
            layer.confirm('确认要删除吗？',function(){
                $.post('{:url("$classuri/del")}',{'id':ids.toString(),'field':'delete'},function(data){
                    if(200 == data.code){
                        //删除行
                        $("#log_table").bootstrapTable('remove',{field:'id',values:ids});
                    }
                    layer.msg(data.msg);
                })
            })
        }
    }
    $('#log_table').bootstrapTable({
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        url:"{:url(\"$classuri/index\")}",
        pageNumber: 1, //初始化加载第一页，默认第一页
        showRefresh: false,
        pagination:true,//是否分页
        sidePagination:'server',//指定服务器端分页
        queryParamsType : "",
        queryParams: function(params){
            return {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
        },//参数
        pageSize:10,//单页记录数
        pageList:[10,20,30,40],//分页步进值
        // responseHandler:responseHandler,//请求数据成功后，渲染表格前的方法
        columns :[
            {checkbox:true,width: 20},
            {field:'id',title:'ID',width:20},
            {field:'username',title:'操作者',width: 80},
            {field:'node',title:'节点',width: 150},
            {field:'action',title:'行为',width: 150},
            {field:'content',title:'操作内容',width: 150},
            {field:'isp',title:'操作位置',width: 150},
            {field:'create_at',title:'操作时间',width: 150}
        ]
    })
    //日期选择插件
    laydate.render({
        elem: '#range-date',
        range: true,
        format: 'yyyy/MM/dd'
    })
</script>
{/block}